<template>
  <a-modal
    :title='currTitle'
    :width='550'
    :visible='visible'
    :closable='false'
    :maskClosable='closable'>
    <template slot='footer'>
      <a-button v-if='closable' @click='close'>关闭</a-button>
      <a-button type='primary' @click='departOk'>确认</a-button>
    </template>

    <a-form layout="inline">
      <a-row>
        <a-col span='3'>
          <a-tooltip placement="topLeft" >
            <template slot="title">
              <span>请选择你要默认展示的学年学期</span>
            </template>
            <a-avatar style="backgroundColor:#87d068" icon="gold" />
          </a-tooltip>
        </a-col>
        <a-col span='10'>
          <a-form-model-item label="学年" prop="schoolYearId">
            <j-dict-select-tag-value v-model="schoolYears" placeholder="请选择学年" style='width: 120px' @change='getText' dictCode="cou_school_year,school_year_name,id"/>
          </a-form-model-item>
        </a-col>
        <a-col span='10'>
          <a-form-model-item label="学期" prop="semesterId">
            <j-dict-select-tag-value v-model="semesters" placeholder="请选择学期" style='width: 120px' dictCode="cou_semester,semester_name,id"/>
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form>

  </a-modal>

</template>

<script>
import { getAction, putAction } from '@/api/manage'
import Vue from 'vue'
import store from '@/store/'
import { YEAR_SEMESTER } from '@/store/mutation-types'
import JDictSelectTagValue from '@comp/dict/JDictSelectTagValue'

export default {
  name: 'YearSemesterSelect',
  components: { JDictSelectTagValue },
  props: {
    title: {
      type: String,
      default: '学期学年选择',
      required: false
    },
    closable: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  watch: {

  },
  data() {
    return {
      currTitle: this.title,
      visible: false,
      validate_status: '',
      schoolYears: '',
      semesters: ''
    }
  },
  created() {

  },
  methods: {
    close() {
      this.departClear()
    },
    getText(){
      console.log(this.schoolYears);
    },
    departOk() {
      if (!this.schoolYears || !this.semesters) {
        this.validate_status = 'error'
        return false
      }
      var yearSemesterInfo = {
        schoolYearId: this.schoolYears.split('^')[0],
        schoolYearName: this.schoolYears.split('^')[1],
        semesterId: this.semesters.split('^')[0],
        semesterName: this.semesters.split('^')[1]
      }
      Vue.ls.remove(YEAR_SEMESTER);
      Vue.ls.set(YEAR_SEMESTER, yearSemesterInfo, 7 * 24 * 60 * 60 * 1000)
      this.departClear();
      window.location.href = window.location.href;
    },
    show() {
      //如果组件传值username此处就不用loadDepartList了
      this.departClear();
      this.visible = true;

    },
    departClear() {
      this.visible = false
      this.validate_status = ''
      this.schoolYearId= ''
      this.semesterId= ''
    }
  }

}
</script>
<style scoped>
.valid-error .ant-select-selection__placeholder {
  color: #f5222d;
}
</style>